Enrich StickyPostgresqlQueueListenerAgent.CheckHealthAsync with listener-state signals (#2647)#2650
Merged
jeremydmiller merged 1 commit intomainfrom May 1, 2026
Merged
Conversation
StickyPostgresqlQueueListenerAgent relied on the default IAgent.CheckHealthAsync —
Status==Running ? Healthy : Unhealthy — which hides the cases that matter most
operationally for sticky per-tenant listeners: the tenant's database becoming
unreachable, the listener latching due to errors, or a backlog growing on a
particular tenant queue.
CheckHealthAsync now layers three persistence signals on top of the agent's
Status:
1. Per-tenant database reachability — `SELECT 1` against the assigned
NpgsqlDataSource via TenantedPostgresqlQueue.PingDatabaseAsync. One failure
⇒ Degraded with the underlying error message; ConsecutiveDbFailureUnhealthyThreshold
(3) consecutive failures ⇒ Unhealthy. Localizes the symptom to the specific
node + tenant pair that's misbehaving — sticky listeners are by definition
pinned, so generic "listener is running" health doesn't catch this.
2. Listener latch state — mirrors what ExclusiveListenerAgent.CheckHealthAsync
does: ask the runtime for the underlying IListeningAgent and translate
ListeningStatus.TooBusy ⇒ Degraded, ListeningStatus.GloballyLatched ⇒
Unhealthy. Same descriptions style (`Listener {queue}/{db}…`) so an operator
sees a consistent shape.
3. Per-tenant queue depth — TenantedPostgresqlQueue.GetQueueDepthAsync runs
`SELECT COUNT(*)` against the parent queue table on the assigned tenant DB.
When the parent endpoint sets a BufferingLimits ceiling, depth ≥ Maximum ⇒
Degraded. Skipped silently when no buffering limit is configured.
Multiple Degraded reasons aggregate into a `;`-joined description so monitoring
tools see the full picture in one tooltip; an Unhealthy reason takes precedence
and pulls Degraded reasons along.
Two helpers landed on TenantedPostgresqlQueue to keep the agent free of raw
NpgsqlCommand plumbing: `PingDatabaseAsync` and `GetQueueDepthAsync`. Both are
internal so the agent assembly can use them and tests in PostgresqlTests can
exercise them directly.
Test plan:
* PostgresqlTests/Transport/sticky_listener_health_tests covers:
- Status precedence (Stopped ⇒ Unhealthy)
- No-endpoint short-circuit (Healthy before StartAsync wires up _tenantEndpoint)
- Description content (mentions queue + tenant)
- PingDatabaseAsync against real Postgres (Should.NotThrow)
- PingDatabaseAsync against a deliberately-broken connection string (Should.Throw)
- GetQueueDepthAsync returning 0 for an empty table
- GetQueueDepthAsync reflecting actual inserted-row counts
* All 7 sticky-listener tests pass locally against the wolverine-postgresql-1
Docker container. Brought NSubstitute into PostgresqlTests so the no-runtime
tests can stub IWolverineRuntime cheaply.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2647.
Summary
StickyPostgresqlQueueListenerAgentrelied on the defaultIAgent.CheckHealthAsync—Status==Running ? Healthy : Unhealthy— which hides the cases that matter most operationally for sticky per-tenant listeners: the tenant's database becoming unreachable, the listener latching due to errors, or a backlog growing on a particular tenant queue.CheckHealthAsyncnow layers three signals on top ofStatus:Per-tenant database reachability —
SELECT 1against the assignedNpgsqlDataSourceviaTenantedPostgresqlQueue.PingDatabaseAsync. One failure ⇒ Degraded with the underlying error message; 3 consecutive failures ⇒ Unhealthy. Localizes the symptom to the specific node + tenant pair that's misbehaving — sticky listeners are by definition pinned, so generic "listener is running" health doesn't catch this.Listener latch state — mirrors what
ExclusiveListenerAgent.CheckHealthAsyncdoes: ask the runtime for the underlyingIListeningAgentand translateListeningStatus.TooBusy⇒ Degraded,ListeningStatus.GloballyLatched⇒ Unhealthy.Per-tenant queue depth —
TenantedPostgresqlQueue.GetQueueDepthAsyncrunsSELECT COUNT(*)against the parent queue table on the assigned tenant DB. When the parent endpoint sets aBufferingLimitsceiling, depth ≥Maximum⇒ Degraded. Skipped silently when no buffering limit is configured.Multiple Degraded reasons aggregate into a
;-joined description so monitoring tools (CritterWatch's Agents tab) see the full picture in one tooltip; an Unhealthy reason takes precedence and pulls Degraded reasons along.API surface
Two
internalhelpers added onTenantedPostgresqlQueueso the agent stays free of rawNpgsqlCommandplumbing:PingDatabaseAsync(CancellationToken)—SELECT 1GetQueueDepthAsync(CancellationToken)—SELECT COUNT(*)on the parent queue tableA test-only
internal int ConsecutiveDbFailureCountaccessor on the agent for diagnostics.Test plan
PostgresqlTests/Transport/sticky_listener_health_testscovers:StartAsyncwires up_tenantEndpoint)PingDatabaseAsyncagainst real Postgres (Should.NotThrow)PingDatabaseAsyncagainst a deliberately-broken connection string (Should.Throw)GetQueueDepthAsyncreturning 0 for an empty tableGetQueueDepthAsyncreflecting actual inserted-row countswolverine-postgresql-1docker container.NSubstituteintoPostgresqlTestsso the no-runtime tests can stubIWolverineRuntimecheaply.🤖 Generated with Claude Code